package com.fnzx.common.config;

import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.baomidou.mybatisplus.core.MybatisConfiguration;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.baomidou.mybatisplus.extension.MybatisMapWrapperFactory;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.apache.ibatis.reflection.MetaObject;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.util.Date;

/**
 * @author: Wang Zhifu
 * @create: 2021/9/12 21:35
 * @Description:
 */
@Configuration
@EnableTransactionManagement
@MapperScan("com.fnzx.dao")
public class MybatisConfig {

    /**
     * 分页插件
     * @return 超过最大页码返回首页，每页最多1000条
     */
    @Bean
    public PaginationInterceptor paginationInterceptor(){
        return new PaginationInterceptor().setOverflow(true).setLimit(1000);
    }


    @Bean
    public ConfigurationCustomizer mybatisConfigurationCustomizer() {
        return new ConfigurationCustomizer() {
            @Override
            public void customize(MybatisConfiguration configuration) {
                configuration.setObjectWrapperFactory(new MybatisMapWrapperFactory());
            }
        };
    }
}
